home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1997 May / EnigmA AMIGA RUN 18 (1997)(G.R. Edizioni)(IT)[!][issue 1997-05][EAR-CD II].iso / softwareupdate / system / amigados / filefunctions / example5.c < prev    next >
C/C++ Source or Header  |  1996-10-10  |  4KB  |  115 lines

  1. /***********************************************************/
  2. /*                                                         */
  3. /* Amiga C Encyclopedia (ACE)           Amiga C Club (ACC) */
  4. /* --------------------------           ------------------ */
  5. /*                                                         */
  6. /* Manual:  AmigaDOS                    Amiga C Club       */
  7. /* Chapter: File Functions              Tulevagen 22       */
  8. /* File:    Example5.c                  181 41  LIDINGO    */
  9. /* Author:  Anders Bjerin               SWEDEN             */
  10. /* Date:    93-03-15                                       */
  11. /* Version: 1.0                                            */
  12. /*                                                         */
  13. /*   Copyright 1993, Anders Bjerin - Amiga C Club (ACC)    */
  14. /*                                                         */
  15. /* Registered members may use this program freely in their */
  16. /*     own commercial/noncommercial programs/articles.     */
  17. /*                                                         */
  18. /***********************************************************/
  19.  
  20. /* This example demonstrates how to alter the protection flags */
  21. /* on a file. The file we used in the previous example         */
  22. /* "HighScore.dat" will be protected and we will then try to   */
  23. /* delete it (unsuccessfully). We will then unprotect the file */
  24. /* and try to delete it again (this time successfully).        */  
  25.  
  26.  
  27.  
  28. /* Include the dos library definitions: */
  29. #include <dos/dos.h>
  30.  
  31. /* Now we include the necessary function prototype files:         */
  32. #include <clib/dos_protos.h>       /* General dos functions...    */
  33. #include <stdio.h>                 /* Std functions [printf()...] */
  34. #include <stdlib.h>                /* Std functions [exit()...]   */
  35.  
  36.  
  37.  
  38. /* Set name and version number: */
  39. UBYTE *version = "$VER: AmigaDOS/FileFunctions/Example5 1.0";
  40.  
  41.  
  42.  
  43. /* Declared our own function(s): */
  44.  
  45. /* Our main function: */
  46. int main( int argc, char *argv[] );
  47.  
  48.  
  49.  
  50. /* Main function: */
  51.  
  52. int main( int argc, char *argv[] )
  53. {
  54.   /* A simple boolean variable: */
  55.   BOOL ok;
  56.  
  57.  
  58.  
  59.   /* Protect the file: (We set the FIBF_DELETE flag which */
  60.   /* will remove the "d" bit. Note that the "e", "w" and  */
  61.   /* "r" bits will be set and "s", "a" and "p" bits       */
  62.   /* removed!)                                            */
  63.   ok = SetProtection( "RAM:HighScore.dat", FIBF_DELETE );
  64.  
  65.   /* Check if the file was successfully protected or not: */
  66.   if( ok )
  67.     printf( "File protected!\n" );
  68.   else
  69.     printf( "Error! Could not protect the file!\n" );
  70.  
  71.  
  72.  
  73.   /* Try to delete the file: (Sould hopefully not work!) */
  74.   ok = DeleteFile( "RAM:HighScore.dat" );
  75.  
  76.   /* Check if the file was deleted or not: */
  77.   if( ok )
  78.     printf( "File deleted!\n" );
  79.   else
  80.     printf( "Error! Could not delete the file!\n" );
  81.  
  82.  
  83.  
  84.   /* Unprotect the file: (We set do not set the FIBF_DELETE */
  85.   /* flag and consequently the "d" bit will be added. Note  */
  86.   /* that the "e", "w" and "r" bits will be set and "s",    */
  87.   /* "a" and "p" bits removed!)                             */
  88.   ok = SetProtection( "RAM:HighScore.dat", NULL );
  89.  
  90.   /* Check if the file was successfully unprotected or not: */
  91.   if( ok )
  92.     printf( "File unprotected!\n" );
  93.   else
  94.     printf( "Error! Could not unprotect the file!\n" );
  95.  
  96.  
  97.  
  98.   /* Try to delete the file: (Sould hopefully work this time!) */
  99.   ok = DeleteFile( "RAM:HighScore.dat" );
  100.  
  101.   /* Check if the file was deleted or not: */
  102.   if( ok )
  103.     printf( "File deleted!\n" );
  104.   else
  105.     printf( "Error! Could not delete the file!\n" );
  106.  
  107.  
  108.  
  109.   /* The End! */
  110.   exit( 0 );
  111. }
  112.  
  113.  
  114.  
  115.